<!DOCTYPE html>
<html>
<head>
	<title>在线工具</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body style="margin:0 auto;width:800px">
     <div style="margin-top:10px">
	 <!--转换后的格式-->
	 请输入区别的重量： <input type="text" id="qujian" name="qujian"/><br/><hr>
     待转换的数据<textarea rows="15" cols="100" id="origin-data"></textarea><br/>
     已转换的数据<textarea rows="15" cols="100" id="new-data"></textarea><br/><br/>
     <button style="width:200px;height:50px;font-size:20px;margin-left:300px;cursor:pointer" onclick="changeData()">转换</button>
     </div>

     <script>
         function changeData(){
             //0-20:100,20-100:20
		     var flagObj = document.getElementById("qujian");
			 //获取隔开符号
			 var flag = flagObj.value;
         	 var origin_data = document.getElementById("origin-data").value;
             //根据换行符分割
             var originArr = origin_data.split("\r\n");
              var sum_str = "";
             for(var i = 0; i < originArr.length ; i++){
               //获取到记录
                var temp_stack = new Array();
               if(originArr[i]!==""){
                   var str = originArr[i];
                   //字符串分割，根据‘,’分割
                   var tempArr = str.split(',');
                   for(var j = 0; j < tempArr.length ; j ++){
                     var tempStr = tempArr[j];
                     //再次进行分割
                     var temp_tempArr1 = tempStr.split(':');
                     var price = temp_tempArr1[1];
                     var weightArr = temp_tempArr1[0].split('-');
                     var weightTemp1 = weightArr[0];
                     var weightTemp2 = weightArr[1];
                     if(parseInt(weightTemp1) >= parseInt(flag)&&weightTemp2!="#"){
                        //以1为单位进行分割
                        var qu = parseInt(weightTemp2)-parseInt(weightTemp1);
                        for(var k = 0; k <=qu; k++ ){
                           var newstr =  (parseInt(weightTemp1)+k)+"-"+(parseInt(weightTemp1)+k)+":"+(((parseInt(weightTemp1)+k))*price).toFixed(2);
                           temp_stack.push(newstr);
                        }
                     }else{
                        //数据放入临时数组
                        temp_stack.push(tempStr);
                     }
                   }
               }
                sum_str += temp_stack.join(',')+"\r\n";
             }
            
         	 //var new_data = origin_data.replace(/\r/ig, "").replace(/\n/ig, flag); 
         	 document.getElementById("new-data").value = sum_str;
         	 copyToClipBoard(new_data);
         	 if ( window.clipboardData ) {
         	 	 window.clipboardData.setData("Text", new_data);  
             	 alert('转换成功，已自动复制转换的内容!');  
         	 }
         }
     </script>
</body>
</html>